<template>
  <div class="table-page-search-wrapper">
    <el-form :model="form" :inline="true" ref="form">
      <el-row :gutter="16">
        <el-col :span="5">
          <el-form-item label="关键字" prop="name">
            <el-input
              clearable
              @keyup.native.enter="handleSearch"
              v-model="form.name"
              placeholder="请输入关键字搜索"
            />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="考评对象" prop="evalTarget">
            <el-select clearable v-model="form.evalTarget">
              <el-option :value="1" label="科室"></el-option>
              <el-option :value="3" label="个人"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="项目分类">
            <classify-select
              @valueChange="handleClassifySelect"
              ref="classifySelect"
              @select="handleClassifySelect"
            />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="奖惩形式" prop="rewardOrientation">
            <el-select clearable v-model="form.rewardOrientation">
              <el-option :value="1" label="分"></el-option>
              <el-option :value="2" label="钱"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item>
            <el-tooltip class="item" content="查询" effect="dark" placement="top">
              <el-button type="primary" @click="handleSearch" icon="el-icon-search" />
            </el-tooltip>
            <el-tooltip class="item" content="重置" effect="dark" placement="top">
              <el-button @click="handleReset" icon="el-icon-refresh-right" />
            </el-tooltip>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import ClassifySelect from './ClassifySelect'
export default {
  components: {
    ClassifySelect
  },
  data() {
    return {
      form: {
        name: null,
        rewardOrientation: null,
        evalTarget: null,
        pageNo: 1
      }
    }
  },
  methods: {
    handleSearch() {
      this.$emit('search', this.form)
    },
    handleReset() {
      this.form.evalTypeId = null
      this.$refs.classifySelect.reset()
      this.$refs.form.resetFields()
      this.$emit('search', this.form)
    },
    handleClassifySelect(value) {
      if (value) {
        this.$set(this.form, 'evalTypeId', value)
      } else {
        this.$set(this.form, 'evalTypeId', null)
      }
    }
  }
}
</script>

<style scoped>
.el-form-item {
  margin-bottom: 0px;
}
</style>